import copy
import json

def _GetAllEntries(log, predicate, entries):
    for entry in log:
        if predicate(entry):
            entries.append(entry)
        _GetAllEntries(entry['children'], predicate, entries)
    return entries

def GetAllEntries(log, predicate):
    return _GetAllEntries(log, predicate, [])

def ListTopLevelCommandsByIndividualRunTime(original_log):
    log = copy.deepcopy(original_log)
    log.sort(key=lambda x: x.end - x.start)
    return log
